package com.face.server.controller;

import com.face.RespMsg;
import com.face.server.entity.Apply;
import com.face.server.entity.Student;
import com.face.server.repository.ApplyRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/client/user/apply")
public class UserApplyController {

    @Autowired
    ApplyRepository applyRepository;

    @GetMapping
    RespMsg findAll(@RequestAttribute String id) {
        return RespMsg.build(applyRepository.findByStudent_Id(id));
    }


    @PostMapping
    RespMsg save(@RequestAttribute String id,
                 @RequestBody @Validated Apply apply) {
        Student student = new Student();
        student.setId(id);
        apply.setStudent(student);
        apply.setApplyTime(new Date());
        applyRepository.save(apply);
        return RespMsg.build(apply.getId());
    }

}


